from django.test import TestCase

# Create your tests here.

import memcache

## 在连接之前，一定要切记先启动memcached
# mc = memcache.Client(["127.0.0.1:11211"],debug=True)

# # 一次只能设置一个值
# mc.set(key='username',val='abc',time=60)
#
# # 一次可以设置多个
# mc.set_multi(mapping={'title':'钢铁是','content':'hello'},time=120)
#
# # 获取值
# username = mc.get('username')
# print(username)
#
# # 删除数据
# mc.delete('username')
# username = mc.get('username')
# print(username)
#
# # 数字增加
# mc.set(key='age',val='20',time=60)
# mc.incr('age',delta=20)     # delta 默认为1
# print(mc.get('age'))
#
# # 数字减少
# mc.decr('age',delta=10)
# print(mc.get('age'))

# 分布式
mc = memcache.Client(["127.0.0.1:11211","192.168.242.9:11211"],debug=True)
mc.set_multi({'username':'zhiliao','age':18,'height':180})